home *** CD-ROM | disk | FTP | other *** search
/ CD BIT 75 / CD BIT 75.iso / Software / ooo / f_0020 / sbasic.jar / text / sbasic / common / 03090410.xml < prev    next >
Encoding:
Extensible Markup Language  |  2003-08-01  |  4.4 KB  |  36 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <html><head><title>Switch Function [Runtime]</title><meta name="filename" content="text/sbasic/common/03090410"/><help:css-file-link xmlns:help="http://openoffice.org/2000/help"/><!--The CSS style header method for setting styles--><style type="text/css">
  3.  
  4.         p.P1{
  5.                 }
  6.         span.T1{
  7.                 font-weight:bold;}
  8.         </style></head><body>
  9.   
  10.   
  11.   <help:paragraphinfo state="E" xmlns:help="http://openoffice.org/2000/help"/><help:to-be-embedded Eid="switch" xmlns:help="http://openoffice.org/2000/help">
  12.   <p class="Head1"><help:paragraphinfo state="U" number="1"/><help:key-word value="Switch; function" tag="kw66497_1"/><help:link Id="66497">Switch Function [Runtime]</help:link></p>
  13.   <p class="Paragraph"><help:paragraphinfo state="U" number="2"/>Evaluates a list of arguments, consisting of an expression followed by a value. The Switch function returns a value that is associated with the expression that is passed by this function.</p>
  14.   <help:paragraphinfo state="E"/></help:to-be-embedded>
  15.   <p class="Head2"><help:paragraphinfo state="U" number="3" xmlns:help="http://openoffice.org/2000/help"/>Syntax:</p>
  16.   <p class="Paragraph"><help:paragraphinfo state="U" number="4" xmlns:help="http://openoffice.org/2000/help"/>Switch (Expression1, Value1[, Expression2, Value2[..., Expression_n, Value_n]])</p>
  17.   <p class="Head2"><help:paragraphinfo state="U" number="5" xmlns:help="http://openoffice.org/2000/help"/>Parameters:</p>
  18.   <p class="Paragraph"><help:paragraphinfo state="U" number="6" xmlns:help="http://openoffice.org/2000/help"/>The <span class="T1">Switch</span> function evaluates the expressions from left to right, and then returns the value that is assigned to the function expression. If expression and value are not given as a pair, a runtime error occurs.</p>
  19.   <p class="Paragraph"><help:paragraphinfo state="U" number="7" xmlns:help="http://openoffice.org/2000/help"/><span class="T1">Expression:</span> The expression that you want to evaluate.</p>
  20.   <p class="Paragraph"><help:paragraphinfo state="U" number="8" xmlns:help="http://openoffice.org/2000/help"/><span class="T1">Value:</span> The value that you want to return if the expression is True.</p>
  21.   <p class="Paragraph"><help:paragraphinfo state="U" number="9" xmlns:help="http://openoffice.org/2000/help"/>In the following example, the <span class="T1">Switch</span> function assigns the appropriate gender to the name that is passed to the function:</p>
  22.   <p class="Paragraph"><help:paragraphinfo state="S" xmlns:help="http://openoffice.org/2000/help"/><help:embedded Id="66475" Eid="errorcode" xmlns:help="http://openoffice.org/2000/help"/></p>
  23.   <p class="Paragraph"><help:paragraphinfo state="S" xmlns:help="http://openoffice.org/2000/help"/><help:embedded Id="66475" Eid="err5" xmlns:help="http://openoffice.org/2000/help"/></p>
  24.   <p class="Head2"><help:paragraphinfo state="U" number="10" xmlns:help="http://openoffice.org/2000/help"/>Example:</p>
  25.   <p class="PropText"><help:paragraphinfo state="U" number="11" xmlns:help="http://openoffice.org/2000/help"/>Sub ExampleSwitch</p>
  26.   <p class="PropText"><help:paragraphinfo state="U" number="12" xmlns:help="http://openoffice.org/2000/help"/>Dim sGender As String</p>
  27.   <p class="PropText"><help:paragraphinfo state="U" number="13" xmlns:help="http://openoffice.org/2000/help"/>sGender = GetGenderIndex( "John" )</p>
  28.   <p class="PropText"><help:paragraphinfo state="U" number="14" xmlns:help="http://openoffice.org/2000/help"/>MsgBox sGender</p>
  29.   <p class="PropText"><help:paragraphinfo state="U" number="15" xmlns:help="http://openoffice.org/2000/help"/>End Sub</p>
  30.   <p class="PropText"><help:paragraphinfo state="U" number="16" xmlns:help="http://openoffice.org/2000/help"/></p>
  31.   <p class="PropText"><help:paragraphinfo state="U" number="17" xmlns:help="http://openoffice.org/2000/help"/>Function GetGenderIndex (sName As String) As String</p>
  32.   <p class="PropText"><help:paragraphinfo state="U" number="18" xmlns:help="http://openoffice.org/2000/help"/>GetGenderIndex = Switch(sName = "Jane", "female", sName = "John", "male")</p>
  33.   <p class="PropText"><help:paragraphinfo state="U" number="19" xmlns:help="http://openoffice.org/2000/help"/>End Function</p>
  34.   <p class="PropText"><help:paragraphinfo state="U" number="20" xmlns:help="http://openoffice.org/2000/help"/></p>
  35.   <p class="PropText"><help:paragraphinfo state="U" number="21" xmlns:help="http://openoffice.org/2000/help"/></p>
  36.  </body></html>